<?php

/******************************************************************************
 *
 *	PROJECT: Flynax Classifieds Software
 *	VERSION: 4.0.1
 *	LISENSE: FL87MPRYOA0R - http://www.flynax.com/license-agreement.html
 *	PRODUCT: Auto Classifieds
 *	DOMAIN: www.siyaradiali.com
 *	FILE: RLCONFIG.CLASS.PHP
 *
 *	This script is a commercial software and any kind of using it must be 
 *	coordinate with Flynax Owners Team and be agree to Flynax License Agreement
 *
 *	This block may not be removed from this file or any other files with out 
 *	permission of Flynax respective owners.
 *
 *	Copyrights Flynax Classifieds Software | 2012
 *	http://www.flynax.com/
 *
 ******************************************************************************/

class rlConfig extends reefless
{
	/**
	* get configuration value by configuration name
	*
	* @param string - configuration variable name
	* @return string - configuration variable value
	*
	**/
	function getConfig( $name )
	{
		if ( empty($GLOBALS['config']) )
		{
			$output = $this -> fetch( array('Default'), array( 'Key' => $name ), null, null, 'config', 'row' );
			
			return $output['Default'];
		}
		else
		{
			return $GLOBALS['config'][$name];
		}
	}
	
	/**
	* set value for configuration
	*
	* @param string $key   - configuration key
	* @param string $value - new value
	*
	**/
	function setConfig( $key, $value )
	{
		$data = array(
			'fields' => array( 'Default' => $value ),
			'where' => array( 'Key' => $key),
		);
		
		if ($GLOBALS['rlActions'] -> updateOne( $data, 'config' ))
		{
			return true;
		}
		
		return false;
	}
	
	/**
	* get all configuration by group id
	*
	* @param string - configuration group id
	* @return array - mixed
	*
	**/
	function allConfig( $group = null )
	{
		$where = !empty( $group )? array( 'Group_ID' => $group ) : "*";
		$output = $this -> fetch( array( 'Key', 'Default' ), $where, null, null, 'config' );
		
		if ( empty($GLOBALS['config']) )
		{
			foreach ($output as $key => $value)
			{
				$configs[$output[$key]['Key']] = $output[$key]['Default'];
			}
			
			$GLOBALS['config'] = $configs;
			
			return $configs;
		}
		else
		{
			return $GLOBALS['config'];
		}
	}
}